From c638ecfd6e36085a0e78cc2ae03654a27fc820b6 Mon Sep 17 00:00:00 2001 From: Robert Lipe Date: Sat, 26 Dec 2020 23:15:06 -0600 Subject: [PATCH] Use full path name when displaying errors opening files for reads and writes. This doesn't work for every place where we issue fatal errors, but it gets the high value formats. --- src/core/file.h | 15 +++++++++++---- util.cc | 12 ++++++++---- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/core/file.h b/src/core/file.h index c6cd70d17..ba130a04a 100644 --- a/src/core/file.h +++ b/src/core/file.h @@ -22,8 +22,10 @@ #include #include +#include #include #include +#include "src/core/logging.h" #include "defs.h" // Mimic gbfile open services @@ -51,10 +53,15 @@ public: } if (!status) { - fatal("Cannot open '%s' for %s. Error was '%s'.\n", - gpsbabel_testmode()? qPrintable(QFileInfo(*this).fileName()) : qPrintable(QFile::fileName()), - (mode & QIODevice::WriteOnly)? "write" : "read", - qPrintable(QFile::errorString())); + fatal(FatalMsg().noquote() << "Cannot open '" % + (gpsbabel_testmode() ? + QFileInfo(*this).fileName() : + QFileInfo(*this).absoluteFilePath()) % + "' for " % + (mode & QIODevice::WriteOnly ? "write" : "read") % + ". Error was '" % + QFile::errorString() % + "'."); } return status; } diff --git a/util.cc b/util.cc index 448f64e3e..1bbc3e4cc 100644 --- a/util.cc +++ b/util.cc @@ -179,8 +179,12 @@ xfopen(const char* fname, const char* type, const char* errtxt) } FILE* f = ufopen(QString::fromUtf8(fname), type); if (nullptr == f) { + // There are some possible vagaries of using Qt for the full pathname + // vs. the STD C library used for the actual file I/O. It's worth it + // to get a better error message. + QFileInfo info(fname); fatal("%s cannot open '%s' for %s. Error was '%s'.\n", - errtxt, fname, + errtxt, qPrintable(info.absoluteFilePath()), am_writing ? "write" : "read", strerror(errno)); } @@ -1760,8 +1764,8 @@ list_codecs() maxlen = codec->name().size(); } } - info << "Available Codecs:" << endl; - info << qSetFieldWidth(8) << "MIBenum" << qSetFieldWidth(maxlen+1) << "Name" << qSetFieldWidth(0) << "Aliases" << endl; + info << "Available Codecs:" << Qt::endl; + info << qSetFieldWidth(8) << "MIBenum" << qSetFieldWidth(maxlen+1) << "Name" << qSetFieldWidth(0) << "Aliases" << Qt::endl; for (auto mib : mibs) { auto codec = QTextCodec::codecForMib(mib); info << qSetFieldWidth(8) << mib << qSetFieldWidth(maxlen+1) << codec->name() << qSetFieldWidth(0); @@ -1775,7 +1779,7 @@ list_codecs() } info << alias; } - info << endl; + info << Qt::endl; } } -- 2.30.2